const Express = require('express');
const App = Express();
const CookieSession = require('cookie-session');
const Post = require('./app/post');
const DB = require('./app/sql');
const bodyParser = require('body-parser');

global.CONFIG = {
    version: 2,
    site: 'http://devs.imconfig.com',
    publicDIR: __dirname + '/app/public'
};
global.ResCode = require('./app/resCode');
global.SESSION = require('./app/session');
global.Logic = require('./app/logic');


App.use(CookieSession({
    name: '$session',
    keys: ['key0', 'key1']
}));
//App.use(bodyParser.urlencoded({ extended: true }));
App.use(bodyParser.json({limit: '11mb'}));

/*app.route('/').get(function(req, res){
    return res.redirect('/#!/index/index');
});*/


DB.initialization(function(db){
    global.DBOpt = db;
    Post.initialization(App);
    App.use(Express.static(__dirname + '/app/public/'));
    const port = 8081;
    App.listen(8081);
    console.log('app listen in ', port);
});

